package com.my.algorithmlearning.leetcode;

import java.util.ArrayList;

/**
 * @ClassName PalindromeNum
 * @Description PalindromeNum
 * @Author wanghaiwei
 * @Date 2022/11/18 18:00
 */
public class PalindromeNum {
    public boolean isPalindrome(int x) {
        if(x < 0) {
            return false;
        }
        ArrayList<Integer> partList = new ArrayList<Integer>();
        int multiplier = x;
        int reminder = 0;
        do {
            reminder = multiplier % 10;
            multiplier = multiplier / 10;
            partList.add(reminder);
        }while(multiplier != 0);
        long result = 0;
        for(int i = 0, j=partList.size(); i < partList.size(); i++,j--){
            result = (long) (result + (partList.get(i) * (Math.pow(10, (j-1)))));
        }
        if(result == x) {
            return true;
        }else {
            return false;
        }
    }

    public static void main(String[] args) {
        System.out.println(new PalindromeNum().isPalindrome(2147483647));
    }
}
